<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>一个多用户博客后台</title>
  <meta name="keywords" content="">
  <meta name="description" content="">
  <link rel="shortcut icon" href="favicon.ico">
  <link href="../public/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
  <link href="../public/css/font-awesome.css?v=4.4.0" rel="stylesheet">
  <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.13.1/bootstrap-table.min.css">
  <link href="../public/css/animate.css" rel="stylesheet">
  <link href="../public/css/style.css?v=4.1.0" rel="stylesheet">
</head>

<body class="gray-bg">
  <div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
      <div class="ibox-title">
        <h5>所有文章</h5>
        <div class="ibox-tools"> <a class="collapse-link"> <i class="fa fa-chevron-up"></i> </a> <a
            class="dropdown-toggle" data-toggle="dropdown" href="#"> <i class="fa fa-wrench"></i> </a>
          <ul class="dropdown-menu dropdown-user">
            <li><a href="#">选项1</a> </li>
            <li><a href="#">选项2</a> </li>
          </ul>
          <a class="close-link"> <i class="fa fa-times"></i> </a>
        </div>
      </div>
      <div class="ibox-content">
        <div class="row row-lg">
          <div class="col-sm-12">
            <!-- Example Events -->
            <div class="example-wrap">
              <div class="example">
                <div class="btn-group hidden-xs" id="exampleTableEventsToolbar" role="group">
                  <button type="button" class="btn btn-outline btn-default" id="past"> <i class="fa fa-flag-checkered"
                      aria-hidden="true"></i>审核 </button>
                      <button type="button" class="btn btn-outline btn-default" id="refuse"> <i class="glyphicon glyphicon-off"
                        aria-hidden="true"></i>关闭</button>
                  <button type="button" class="btn btn-outline btn-default" id="delate"> <i class="glyphicon glyphicon-trash"
                      aria-hidden="true"></i>删除 </button>
                </div>
                <table id="cmtslist" data-height="550" data-mobile-responsive="true">
                  <thead>
                    <tr>
                      <th data-checkbox="true"></th>
                      <th data-field="xuhao" data-formatter="xuhao">序号</th>
                      <th data-field="isOK" data-formatter="isOK">状态</th>
                      <th data-field="_id">ID</th>
                      <th data-field="artid.title"  data-formatter="docUrl">文章</th>
                      <th data-field="replyName">评论人</th>
                      <th data-field="content">评论内容</th>
                      <th data-field="time">评论时间</th>
                      <th data-field="replyBody" data-formatter="length">热议数</th>
                      <!-- <th data-field="doc" data-formatter="docUrl">文档</th> -->
                      <th data-formatter="actionFormatter" data-align="center">回复</th>
                    </tr>
                  </thead>
                </table>
              </div>
            </div>
            <!-- End Example Events -->
          </div>
        </div>
      </div>
    </div>
    <!-- End Panel Other -->
  </div>

  <!-- 全局js -->
  <script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <!-- 自定义js -->
  <script src="../public/js/content.js?v=1.0.0"></script>

  <!-- Bootstrap table -->
  <script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.13.1/bootstrap-table.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.13.1/locale/bootstrap-table-zh-CN.min.js"></script>

  <!-- Peity -->
  <script>
    function EditViewById(id) {
      console.log(id)
    }

    function getSelectRow() {
      console.log($("#exampleTableEvents").bootstrapTable('getSelections'))
    }
    //操作栏的格式化
    function actionFormatter(value, row, index) {
      var id = row._id;
      var result = "";
      result +="<a href='/cmtsInfo"+ id  +"' class='btn btn-xs blue' title='编辑'><span class='glyphicon glyphicon-pencil'></span></a>";
      return result;
    }

    function docUrl(value, row, index) {
      var result = `<a href="/category${row.cateid }/${row.artid._id}" target='_blank'>${value}</a>`;
      return result;
    }
    function isOK(value, row, index){
      return row.isOK?'<span style="color:green">已审核</span>':'<span style="color:red">未审核</span>'
    }
    function length(value) {
      return value.length;
    }

    function xuhao(value, row, index) {
      var pageNumber = $('#cmtslist').bootstrapTable('getOptions').pageNumber;
      var pageSize = $('#cmtslist').bootstrapTable('getOptions').pageSize;
      return (pageNumber - 1) * pageSize + index + 1;
    }

    $('#cmtslist').bootstrapTable({
      url: "/getAllCmts",
      search: true,
      method: 'get',
      pagination: true,
      showRefresh: true,
      showColumns: true,
      contentType: "application/x-www-form-urlencoded; charset=UTF-8",
      iconSize: 'outline',
      toolbar: '#exampleTableEventsToolbar',
      icons: {
        refresh: 'glyphicon-repeat',
        columns: 'glyphicon-list'
      }
    });
    $('#cmtslist').bootstrapTable('hideColumn', '_id'); //隐藏_id

    function dosome(url){
      var row = $("#cmtslist").bootstrapTable('getSelections')
      var idArr =[]
      row.forEach(item => {
        idArr.push(item._id)
      });
      var arr = idArr.toString()
      $.ajax({
        url,
        type:'GET',
        data:{
          arr
        },
        success:function(res){
          if(res.code==1){
            $("#cmtslist").bootstrapTable('refresh')
          }
          if(res.code==0||res.code==-1){
            alert(res.msg)
          }
        }
      })



    }

    //审核评论
    $('#past').click(function(){
      dosome('/pastCmts')

    })
    $('#delate').click(function(){
      dosome('/deleteCmt')
    })
    $('#refuse').click(function(){
      dosome('/refuseCmt')
    })


  </script>
</body>

</html>